# CMake 的组态档取名为 CMakeLists.txt
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

#声明要求的cmake最低版本
cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.


#这条命令告诉 cmake,我想把这个文件（native-lib.cpp）编译成一个叫做“native-lib”的库。然后使用 cmake 编译整个工程:
#添加一个库
#语法：add_library( 库名称 源代码文件 ），会生成 lib库名称.a（静态库）
#语法：add_library( 库名称 SHARED 源代码文件 ），会生成 lib库名称.so （共享库）
add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             # 静态库以.a 作为后缀名,共享库以.so结尾      所有库都是一些函数打包后的集合,差别在于静态库每次被调用都会生成一个副本,而共享库则只有一个副本,更省空间。
             SHARED

             # Provides a relative path to your source file(s).
             src/main/cpp/native-lib.cpp )
add_library(native-lib-sturct SHARED src/main/cpp/native-lib-sturct.cpp)
add_library(test-regist-native-method SHARED src/main/cpp/test-regist-native-method.cpp)


add_library(breath_led SHARED src/main/cpp/breath_led.cpp)
# 将libbreathled.so作为一个导入的库添加到构建中
add_library(breathled SHARED IMPORTED)
#set_target_properties(breathled PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/libbreathled.so)
set_target_properties(breathled PROPERTIES IMPORTED_LOCATION /Users/macpro/Android/worksapce/JniProject/app/src/main/jniLibs/libbreathled.so)


# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

#target_link_libraries(<target> [item1] [item2] [...]
#        [[debug|optimized|general] <item>] ...)
#<target>是指通过add_executable()和add_library()指令生成已经创建的目标文件
#将可执行程序链接到库
#语法：target_link_libraries ( 程序名 库名称 ）
target_link_libraries( # Specifies the target library.
                       native-lib


                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

target_link_libraries(
        native-lib-sturct
        ${log-lib} )
target_link_libraries(
        test-regist-native-method
        ${log-lib} )

#target_link_libraries(breath_led ${log-lib})
target_link_libraries(breath_led breathled ${log-lib})

#target_link_libraries(hello libhello)  添加了一个新的目标 libhello，并将其链接进hello程序(libhello 可以是add_library生成的库) #todo 待测试

